package com.itheima.day15.TCP.test6;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

public class ClientDemo {
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        Socket s = new Socket("192.168.23.34", 10007);

        lo:
        while (true) {
            System.out.println("请输入：");
            String string = sc.nextLine();

            // 上传文字到服务器
            OutputStream os = s.getOutputStream();
            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(os));
            bw.write(string);
            bw.newLine();
            bw.flush();
            s.shutdownOutput();

            InputStream is = s.getInputStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(is));
            String str;
            while ((str = br.readLine()) != null) {
                System.out.println(str);
                if ("服务器关闭".equals(str))
                    break lo;
            }

        }
        s.close();
    }
}
